package sword;

/**
 * s1 abc -
 * s2 bdabcf +
 *
 * @author K
 * @date 2021-12-02 19:17
 */
public class Solution {
    public static boolean s(String s1, String s2) {
        int[] counts = new int[26];
        for (int i = 0; i < s1.length(); i++) {
            counts[s2.charAt(i) - 'a']++;
            counts[s1.charAt(i) - 'a']--;
        }
        if (allZero(counts)) {
            return true;
        }
        for (int i = s1.length(); i < s2.length(); i++) {
            counts[s2.charAt(i) - 'a']++;
            counts[s2.charAt(i-s1.length()) -'a']--;
            if (allZero(counts)) {
                return true;
            }
        }
        return false;
    }

    private static boolean allZero(int[] counts) {
        for (int count : counts) {
            if (count != 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        double v = Math.random() * 9 + 1;
        double v1 = v * 100000;
        String s1 = "abc";
        String s2 = "bfsdabc";
        boolean result = s(s1, s2);
        System.out.println();
    }
}
